package com.burst.reptile.modular.zp.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.burst.reptile.framework.web.controller.BaseController;
import com.burst.reptile.framework.web.result.LayuiResult;
import com.burst.reptile.framework.web.result.Result;
import com.burst.reptile.modular.zp.entity.ZpReport;
import com.burst.reptile.modular.zp.form.ReportForm;
import com.burst.reptile.modular.zp.service.IZpReportService;
import com.burst.reptile.modular.zp.warpper.ZpReportWrapper;

import lombok.RequiredArgsConstructor;

/**
 * <p>
 * 举报信息 前端控制器
 * </p>
 *
 * @author wujin
 * @since 2020-06-29
 */
@RestController
@RequestMapping("/zp/report")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ZpReportController extends BaseController{
	
	private final IZpReportService reportService;

	/**
	 * 举报
	 * @param reportForm
	 * @return
	 */
	@PostMapping("/article")
	public Result<Object> report(@Validated @RequestBody ReportForm reportForm){
		return Result.success(reportService.report(reportForm));
	}
	
	/**
	 * 举报列表
	 * @param report
	 * @return
	 */
	@GetMapping("/list")
	@PreAuthorize("@ss.hasPermi('zp:report:list')")
	public LayuiResult<Object> list(ZpReport report){
		Page<ZpReport> page = startPage();
		Page<ZpReport> pageList = reportService.pageList(page, report);
		new ZpReportWrapper(pageList).wrap();
		return LayuiResult.success(pageList.getTotal(), pageList.getRecords());
	}
	
	/**
	 * 处理
	 * @param report
	 * @return
	 */
	@PostMapping("/edit")
	@PreAuthorize("@ss.hasPermi('zp:report:edit')")
	public LayuiResult<Object> edit(@RequestBody ZpReport report){
		return LayuiResult.success(reportService.updateById(report));
	}
	
}
